package dht.tool;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import dht.throwable.DhtException;

public class CommandTool {
	public static int runCommand(String cmd) throws DhtException {
		System.out.println("run command: " + cmd);
		Runtime run = Runtime.getRuntime();
		try {
			Process p = run.exec(cmd);
			BufferedInputStream in = new BufferedInputStream(p.getInputStream());
			BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
			String lineStr;
			while ((lineStr = inBr.readLine()) != null)
				System.out.println(lineStr);
			inBr.close();
			in.close();
			return p.waitFor();
		} catch (Exception e) {
			throw new DhtException(e.getMessage());
		}
	}
}
